/*
 * CustomContainer.cpp
 *
 *  Created on: 2011-1-9
 *      Author: Administrator
 */

#include "CustomContainer.h"
#include "ContainerControl.h"
#include "ListBox.h"

CCustomContainer* CCustomContainer::NewL(const TRect& aRect, const CCoeControl* aParent)
	{
	CCustomContainer* self = CCustomContainer::NewLC(aRect,aParent);
	CleanupStack::Pop(self);
	return self;
	}

CCustomContainer* CCustomContainer::NewLC(const TRect& aRect, const CCoeControl* aParent)
	{
	CCustomContainer* self = new(ELeave) CCustomContainer();
	CleanupStack::PushL(self);
	self->ConstructL(aRect,aParent);
	return self;
	}

CCustomContainer::CCustomContainer()
	{
	// TODO Auto-generated constructor stub

	}

CCustomContainer::~CCustomContainer()
	{
	// TODO Auto-generated destructor stub
	}

void CCustomContainer::UpdateControls(TInt aOffset, TBool aChangeCurPos)
	{
    TInt count=Components().Count();
	if ( count<= 0)
		return ;
	TPoint position;
	iTotalHeight = 0;
    // Goes through all components of this container control
    CCoeControlArray::TCursor cursor = Components().Begin();
    CCoeControl* ctrl = NULL;
    CContainerControl* container = NULL;
    CListBox* list = NULL;
    if (aChangeCurPos)
    	iCurPos -= aOffset;
    if (iScrollDirection == EVertical)
    	{
		while ((ctrl = cursor.Control<CCoeControl>()) != NULL)
			{
			position = ctrl->Position();
			position.iY += aOffset;
			if (!aChangeCurPos)
				position.iX += Rect().iTl.iX;
			ctrl->SetPosition(position);
	
			if ( IsInRect(ctrl) )
				{
				ctrl->MakeVisible(ETrue);
				}
			else
				{
				ctrl->MakeVisible(EFalse);
				}
			iTotalHeight = ctrl->Rect().iBr.iY;
			cursor.Next();
			}
    	}
    else
    	{
		while ((ctrl = cursor.Control<CCoeControl>()) != NULL)
			{
			position = ctrl->Position();
			position.iX += aOffset;
			if (!aChangeCurPos)
				position.iY += Rect().iTl.iY;
			ctrl->SetPosition(position);
	
			if ( IsInRect(ctrl) )
				{
				ctrl->MakeVisible(ETrue);
				}
			else
				{
				ctrl->MakeVisible(EFalse);
				}
			iTotalHeight = ctrl->Rect().iBr.iX;
			cursor.Next();
			}
    	}
    iTotalHeight -= iFirstControl->Position().iY;
    UpdateScrollBarFrameL();
	}
